/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.wcalendar.business.security.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.primefaces.model.ScheduleEvent;

/**
 *
 * @author gugu
 */
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")

@Table(name = "event")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e"),
    @NamedQuery(name = "Event.findByDistrict", query = "SELECT e FROM Event e WHERE e.place = :place"),
    @NamedQuery(name = "Event.findByIde", query = "SELECT e FROM Event e WHERE e.ide = :ide"),
    @NamedQuery(name = "Event.findByPrivacy", query = "SELECT e FROM Event e WHERE e.privacy = :privacy"),
    @NamedQuery(name = "Event.findByDescription", query = "SELECT e FROM Event e WHERE e.description = :description"),
    @NamedQuery(name = "Event.findByInOut", query = "SELECT e FROM Event e WHERE e.inOut = :inOut"),
    @NamedQuery(name = "Event.findByDate", query = "SELECT e FROM Event e WHERE e.date = :date"),
    @NamedQuery(name = "Event.findByDate_end", query = "SELECT e FROM Event e WHERE e.data_end = :data_end"),
    @NamedQuery(name = "Event.findByCreator", query = "SELECT e FROM Event e WHERE e.creator = :creator")})
public class Event implements Serializable, ScheduleEvent {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "Id_e")
    private Integer ide;
    @Basic(optional = false)
    @NotNull
    @Column(name = "privacy")
    private boolean privacy;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "in_out")
    private boolean inOut;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "data_end")
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    private Date data_end;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event1")
    private Collection<Notification> notificationCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<PeopleInvited> peopleInvitedCollection;
    @JoinColumn(name = "place", referencedColumnName = "Id_d")
    @ManyToOne(optional = false)
    private District place;
    @JoinColumn(name = "creator", referencedColumnName = "Nickname")
    @ManyToOne(optional = false)
    private User creator;

    public Event() {
    }

    public Event(Integer ide) {
        this.ide = ide;
    }

    public Event(Integer ide, boolean privacy, String description, boolean inOut, Date date, Date date_end) {
        this.ide = ide;
        this.privacy = privacy;
        this.description = description;
        this.inOut = inOut;
        this.date = date;
        this.data_end = date_end;
    }

    public Event(boolean privacy, String description, boolean inOut, Date date, Date date_end) {
        this.privacy = privacy;
        this.description = description;
        this.inOut = inOut;
        this.date = date;
        this.data_end = date_end;
    }

    public Integer getIde() {
        return ide;
    }

    public void setIde(Integer id) {
        this.ide = id;
    }

    public boolean getPrivacy() {
        return privacy;
    }

    public void setPrivacy(boolean privacy) {
        this.privacy = privacy;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean getInOut() {
        return inOut;
    }

    public void setInOut(boolean inOut) {
        this.inOut = inOut;
    }

    @Override
    public Date getData() {
        return date;
    }

    public Date getData_end() {
        return data_end;
    }

    public void setStartDate(Date startDate) {
        this.date = startDate;
    }

    public void setEndDate(Date endDate) {
        this.data_end = endDate;
    }

    @XmlTransient
    public Collection<Notification> getNotificationCollection() {
        return notificationCollection;
    }

    public void setNotificationCollection(Collection<Notification> notificationCollection) {
        this.notificationCollection = notificationCollection;
    }

    @XmlTransient
    public Collection<PeopleInvited> getPeopleInvitedCollection() {
        return peopleInvitedCollection;
    }

    public void setPeopleInvitedCollection(Collection<PeopleInvited> peopleInvitedCollection) {
        this.peopleInvitedCollection = peopleInvitedCollection;
    }

    public District getPlace() {
        return place;
    }

    public void setPlace(District place) {
        this.place = place;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ide != null ? ide.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.ide == null && other.ide != null) || (this.ide != null && !this.ide.equals(other.ide))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.wcalendar.business.security.Event[ ide=" + ide + " ]";
    }

    @Override
    public String getId() {
        return ide.toString();
    }

    @Override
    public void setId(String string) {
    }

    @Override
    public String getTitle() {
        return description;
    }

    @Override
    public Date getStartDate() {
        return date;
    }

    @Override
    public Date getEndDate() {
        return data_end;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public boolean isAllDay() {
        return false;
    }

    @Override
    public String getStyleClass() {
        return null;
    }

    @Override
    public boolean isEditable() {
        return false;
    }

}
